package record.test;

import com.google.gson.Gson;
import org.junit.Test;
import record.core.RecordCreateService;
import record.test.workFlowInfo.InComeCondition;
import record.test.workFlowInfo.WorkFlow;
import record.test.workFlowInfo.WorkFlowNode;
import record.treeResult.Item;

import java.util.ArrayList;
import java.util.List;

/**
 * @Package: com.Record.Test
 * @ClassName: Main
 * @Author: wulongkai
 * @CreateTime: 2023/12/19 15:01
 * @Description:
 */
public class Main {
    Gson gson = new Gson();

    private WorkFlow getOldBean() {
        InComeCondition inComeCondition = new InComeCondition();
        inComeCondition.setRule(1);
        WorkFlowNode workFlowNode = new WorkFlowNode();
        workFlowNode.setId(1001);
        workFlowNode.setWorkFlowNodeName("工作流头节点");
        workFlowNode.setNumber(0);
        workFlowNode.setInComeCondition(inComeCondition);

        InComeCondition inComeCondition2 = new InComeCondition();
        inComeCondition2.setRule(2);
        List<WorkFlowNode> workFlowNodeList = new ArrayList<>();
        WorkFlowNode workFlowNode2 = new WorkFlowNode();
        workFlowNode2.setId(1002);
        workFlowNode2.setWorkFlowNodeName("发起工作流");
        workFlowNode2.setNumber(0);
        workFlowNode2.setInComeCondition(inComeCondition2);
        WorkFlowNode workFlowNode3 = new WorkFlowNode();
        workFlowNode3.setId(1003);
        workFlowNode3.setWorkFlowNodeName("自评");
        workFlowNode3.setNumber(1);
        workFlowNode3.setInComeCondition(inComeCondition2);
        workFlowNodeList.add(workFlowNode2);
        workFlowNodeList.add(workFlowNode3);

        WorkFlow workFlow = new WorkFlow();
        workFlow.setWorkFlowName("转正工作流");
        workFlow.setWorkFlowType(1);
        workFlow.setPriority(1);
        workFlow.setWorkFlowNode(workFlowNode);
        workFlow.setWorkFlowNodeList(workFlowNodeList);
        return workFlow;
    }

    private WorkFlow getNewBean() {
        InComeCondition inComeCondition = new InComeCondition();
        inComeCondition.setRule(2);
        WorkFlowNode workFlowNode = new WorkFlowNode();
        workFlowNode.setId(1001);
        workFlowNode.setWorkFlowNodeName("工作流头节点2");
        workFlowNode.setNumber(0);
        workFlowNode.setInComeCondition(inComeCondition);

        InComeCondition inComeCondition2 = new InComeCondition();
        inComeCondition2.setRule(1);
        List<WorkFlowNode> workFlowNodeList = new ArrayList<>();
        WorkFlowNode workFlowNode2 = new WorkFlowNode();
        workFlowNode2.setId(1002);
        workFlowNode2.setWorkFlowNodeName("发起工作流2");
        workFlowNode2.setNumber(0);
        workFlowNode2.setInComeCondition(inComeCondition2);
        WorkFlowNode workFlowNode3 = new WorkFlowNode();
        workFlowNode3.setId(1003);
        workFlowNode3.setWorkFlowNodeName("审批");
        workFlowNode3.setNumber(1);
        workFlowNode3.setInComeCondition(inComeCondition2);
        workFlowNodeList.add(workFlowNode2);
        workFlowNodeList.add(workFlowNode3);

        WorkFlow workFlow = new WorkFlow();
        workFlow.setWorkFlowName("转正工作流2");
        workFlow.setWorkFlowType(1);
        workFlow.setPriority(2);
        workFlow.setWorkFlowNode(workFlowNode);
        workFlow.setWorkFlowNodeList(workFlowNodeList);
        return workFlow;
    }

    @Test
    public void test6() {
        // 更新
        Item publishRecord = RecordCreateService.createPublishRecord(getOldBean(), getNewBean());
        System.out.println(gson.toJson(publishRecord));
        publishRecord.getSubItem().get(0).print();

        // 删除
        Item deleteRecord = RecordCreateService.createPublishRecord(getOldBean(), null);
        System.out.println(gson.toJson(deleteRecord));

        // 新增
        Item addRecord = RecordCreateService.createPublishRecord(null, getNewBean());
        System.out.println(gson.toJson(addRecord));
    }
}
